#!/bin/sh -e

manage="/path/to/manage.py"
user="user"
PID="/path/to/django_fcgi.pid"

. $home/private/python/bin/activate
test `id -u` -eq 0 && su - $user -s /bin/bash
usage="$0 {start|stop|restart}"

case $1 in
    start)
        $manage runfcgi method=prefork daemonize=True host=127.0.0.1 port=8888 maxrequests=500 pidfile=$PID
    ;;
    stop)
        test -f $PID && kill `cat $PID`|| echo "Not running"
    ;;
    restart)
        $0 stop
        $0 start
    ;;
    *)
        echo usage
        exit 1
    ;;
esac

exit 0
